package com.zzx.shiro.exceptions;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName: NoPermissionException
 * @Description: SpringBoot异常拦截器
 * @Author zhouzhixin
 * @Date 2021/9/15
 * @Version 1.0
 */
@ControllerAdvice
public class NoPermissionException {

    @ExceptionHandler(UnauthorizedException.class)
    public String unauthorizedException(Exception ex) {
        return "noAuth";
    }

    @ResponseBody
    @ExceptionHandler(AuthorizationException.class)
    public String authorizationException(Exception ex) {
        return "权限认证失败";
    }

    @ResponseBody
    @ExceptionHandler(AuthenticationException.class)
    public String authenticationException(Exception ex) {
        return "用户名或密码不正确";
    }

}
